package com.example.mvvm.view.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;

import androidx.annotation.NonNull;

import com.example.mvvm.R;

public class DialogHelper extends Dialog {

    private WebView webView;
    private View view;

    public DialogHelper(@NonNull Context context) {
        this(context, R.style.user_default_dialog);
    }

    public DialogHelper(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        view = LayoutInflater.from(context).inflate(R.layout.helper_dialog, null, false);
        webView = view.findViewById(R.id.helper_web);

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        if (window == null) return;
        //window.setGravity(gravity);
        setContentView(view);
        WindowManager.LayoutParams lp = window.getAttributes();
        //lp.width = width;// 设置dialog宽度
        //lp.height = height;// 设置dialog宽度
        window.setAttributes(lp);
        //setCanceledOnTouchOutside(false);//点击外部Dialog消失
        //setCancelable(false);
    }


    public static DialogHelper getInstance(Context context) {
        return new DialogHelper(context);
    }

    public DialogHelper setUrl(String desc) {
        webView.loadDataWithBaseURL(null, desc, "text/html", "utf-8", null);
        return this;
    }

}
